package com.tiancheng.onecode.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

/**
 * 商户清分规则状态枚举
 *
 * @author konkera
 * @date 2021/7/15
 */
@Getter
@AllArgsConstructor
public enum MerchantSettleRuleStatusEnum {
    EFFECTIVE(1, "生效"),
    INVALIDATION(2, "失效"),
    ;

    private final Integer value;
    private final String name;

    /**
     * 根据值获取描述
     *
     * @param value {@link Integer}
     * @return {@link String}
     */
    public String getNameByValue(Integer value) {
        return Arrays.stream(values()).filter(d -> Objects.equals(value, d.getValue())).findFirst()
                .map(MerchantSettleRuleStatusEnum::getName).orElse("");
    }

    /**
     * 根据值获取枚举
     *
     * @param value {@link Integer}
     * @return {@link MerchantSettleRuleStatusEnum}
     */
    public static MerchantSettleRuleStatusEnum getByValue(Integer value) {
        return Arrays.stream(values()).filter(d -> Objects.equals(value, d.getValue())).findFirst().orElse(null);
    }
}
